package com.tencent.sr.iris.activity.service.task.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.tencent.sr.bizmid.user.core.interfaces.dto.ChannelUserIdentifyDTO;
import com.tencent.sr.bizmid.user.core.interfaces.dto.UserChannelAccountDTO;
import com.tencent.sr.bizmid.user.core.interfaces.dto.UserCoreDTO;
import com.tencent.sr.bizmid.user.core.interfaces.enums.UserGroup;
import com.tencent.sr.bizmid.user.core.interfaces.request.BatchQueryChannelAccountRequest;
import com.tencent.sr.bizmid.user.core.interfaces.response.ChannelAccountQueryResponse;
import com.tencent.sr.iris.activity.common.config.IrisThreadPoolConfig;
import com.tencent.sr.iris.activity.common.constant.QuFaHttpConstant;
import com.tencent.sr.iris.activity.common.enums.IsAdviserEnum;
import com.tencent.sr.iris.activity.common.enums.TaskStatusEnum;
import com.tencent.sr.iris.activity.dependency.dto.common.GroupTaskBoardUtils;
import com.tencent.sr.iris.activity.dependency.dto.common.OperateBoardUtils;
import com.tencent.sr.iris.activity.dependency.dto.group.AdvisorBoardDTO;
import com.tencent.sr.iris.activity.dependency.dto.group.OperateBoardStatisticsDTO;
import com.tencent.sr.iris.activity.dependency.dto.group.OperateSecondBoardDTO;
import com.tencent.sr.iris.activity.dependency.dto.group.OperateThirdBoardDTO;
import com.tencent.sr.iris.activity.dependency.dto.group.SpecialStageListsDTO;
import com.tencent.sr.iris.activity.dependency.dto.group.UnJoinTaskDTO;
import com.tencent.sr.iris.activity.dependency.operate.OperateBoardDependency;
import com.tencent.sr.iris.activity.dependency.qufa.GroupTaskBoardNewDependency;
import com.tencent.sr.iris.activity.dependency.user.UserCoreDependency;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.CanJoinTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardStatisticsRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardThirdRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.SpecialStageListsRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.UnJoinTaskRequest;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.GroupTaskPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.*;
import com.tencent.sr.iris.activity.service.task.OperateBoardService;
import com.tencent.sr.iris.user.core.service.interfaces.dto.tutor.UserTutorRelationDTO;
import com.tencent.sr.iris.user.core.service.interfaces.dto.user.UserWideDTO;
import com.tencent.sr.iris.user.core.service.interfaces.request.tutor.StudentQueryRequest;
import com.tencent.sr.iris.user.core.service.interfaces.request.user.IrisUserWideListQueryRequest;
import com.tencent.sr.iris.user.core.service.interfaces.response.user.UserWideListResponse;
import com.tencent.sr.rmall.common.exception.retail.TRetailBizException;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Component
public class OperateBoardServiceImpl implements OperateBoardService {

    @Resource
    private OperateBoardDependency operateBoardDependency;
    @Resource
    private UserCoreDependency userCoreDependency;
    @Resource(name = IrisThreadPoolConfig.IRIS_QUERY_EXECUTOR)
    private ExecutorService queryExecutor;

    @Resource
    private GroupTaskBoardNewDependency groupTaskBoardNewDependency;


    @Override
    public PaginationResponse<OperateBoardInviteResponse> queryOperateBoardInvite(
            PaginationRequest<OperateBoardRequest> request) {
        String advisorUid = request.getQueryCriteria().getAdviserId();
        UserCoreDTO advisor = null;
        if (!StringUtils.isEmpty(advisorUid)) {
            //List<String> tutorRelations = getTutorRelations(advisorUid, request.getQueryCriteria().getSaasId());
            //if (CollectionUtils.isEmpty(tutorRelations)) {
            //    return new PaginationResponse();
            //} else {
            //  request.getQueryCriteria().setWechatUserUnionIds(tutorRelations);
            request.getQueryCriteria().setIsAdviser(IsAdviserEnum.ADVISER.getStatus());
            advisor = getUserByAdvisorUid(advisorUid);
            //}
        }
        PaginationResponse<OperateBoardInviteResponse> response = operateBoardDependency.queryOperateInvite(request,
                QuFaHttpConstant.OPERATE_INVITE);
        if (!CollectionUtils.isEmpty(response.getDataList())) {
            List<OperateBoardInviteResponse> dataList = response.getDataList();

            for (OperateBoardInviteResponse inviteResponse : dataList) {
                UserCoreDTO userCoreDTO;
                if (Objects.nonNull(advisor)) {
                    userCoreDTO = advisor;
                } else {
                    userCoreDTO = getUserTutorName(inviteResponse.getIrisUid());
                }
                inviteResponse.setAdvisorHeadUrl(userCoreDTO.getHeadUrl());
                inviteResponse.setAdvisorNickName(userCoreDTO.getNickName());
                inviteResponse.setAdvisorUid(userCoreDTO.getUid());
            }
        }
        return response;
    }

    @Override
    public PaginationResponse<OperateBoardSprintResponse> queryOperateBoardSprint(
            PaginationRequest<OperateBoardRequest> request) {
        String advisorUid = request.getQueryCriteria().getAdviserId();
        UserCoreDTO advisor = null;
        if (!StringUtils.isEmpty(request.getQueryCriteria().getAdviserId())) {
            //List<String> tutorRelations = getTutorRelations(advisorUid, request.getQueryCriteria().getSaasId());
            //if (CollectionUtils.isEmpty(tutorRelations)) {
            //    return new PaginationResponse();
            //} else {
            //   request.getQueryCriteria().setWechatUserUnionIds(tutorRelations);
            request.getQueryCriteria().setIsAdviser(IsAdviserEnum.ADVISER.getStatus());
            advisor = getUserByAdvisorUid(advisorUid);
            //}
        }
        PaginationResponse<OperateBoardSprintResponse> response = operateBoardDependency.queryOperateSprint(request,
                QuFaHttpConstant.OPERATE_SPRINT);
        if (!CollectionUtils.isEmpty(response.getDataList())) {
            List<OperateBoardSprintResponse> dataList = response.getDataList();
            for (OperateBoardSprintResponse sprintResponse : dataList) {
                UserCoreDTO userCoreDTO;
                if (Objects.nonNull(advisor)) {
                    userCoreDTO = advisor;
                } else {
                    userCoreDTO = getUserTutorName(sprintResponse.getIrisUid());
                }
                sprintResponse.setAdvisorHeadUrl(userCoreDTO.getHeadUrl());
                sprintResponse.setAdvisorNickName(userCoreDTO.getNickName());
                sprintResponse.setAdvisorUid(userCoreDTO.getUid());
            }
        }
        return response;
    }

    @Override
    public PaginationResponse<OperateBoardCommissionResponse> queryOperateBoardCommission(
            PaginationRequest<OperateBoardRequest> request) {
        String advisorUid = request.getQueryCriteria().getAdviserId();
        UserCoreDTO advisor = null;
        if (!StringUtils.isEmpty(advisorUid)) {
            //List<String> tutorRelations = getTutorRelations(advisorUid, request.getQueryCriteria().getSaasId());
            //if (CollectionUtils.isEmpty(tutorRelations)) {
            //    return new PaginationResponse();
            //} else {
            //    request.getQueryCriteria().setWechatUserUnionIds(tutorRelations);
            request.getQueryCriteria().setIsAdviser(IsAdviserEnum.ADVISER.getStatus());
            advisor = getUserByAdvisorUid(advisorUid);
            //}
        }
        PaginationResponse<OperateBoardCommissionResponse> response = operateBoardDependency.queryOperateCommission(
                request, QuFaHttpConstant.OPERATE_COMMISSION);
        if (!CollectionUtils.isEmpty(response.getDataList())) {
            List<OperateBoardCommissionResponse> dataList = response.getDataList();
            for (OperateBoardCommissionResponse commissionResponse : dataList) {
                UserCoreDTO userCoreDTO;
                if (Objects.nonNull(advisor)) {
                    userCoreDTO = advisor;
                } else {
                    userCoreDTO = getUserTutorName(commissionResponse.getIrisUid());
                }
                commissionResponse.setAdvisorHeadUrl(userCoreDTO.getHeadUrl());
                commissionResponse.setAdvisorNickName(userCoreDTO.getNickName());
                commissionResponse.setAdvisorUid(userCoreDTO.getUid());
            }
        }
        return response;
    }

    @Override
    public PaginationResponse<OperateBoardFirstOrderResponse> queryOperateFirstOrder(
            PaginationRequest<OperateBoardRequest> request) {
        String advisorUid = request.getQueryCriteria().getAdviserId();
        if (!StringUtils.isEmpty(advisorUid)) {
            //List<String> tutorRelations = getTutorRelations(advisorUid, request.getQueryCriteria().getSaasId());
            //if (CollectionUtils.isEmpty(tutorRelations)) {
            //    return new PaginationResponse<>();
            //} else {
            //request.getQueryCriteria().setWechatUserUnionIds(tutorRelations);
            request.getQueryCriteria().setIsAdviser(IsAdviserEnum.ADVISER.getStatus());
            //}
        }

        PaginationResponse<OperateBoardFirstOrderResponse> response = operateBoardDependency.queryOperateFirstOrder(
                request, QuFaHttpConstant.OPERATE_FIRST_ORDER);
        if (!CollectionUtils.isEmpty(response.getDataList())) {
            List<OperateBoardFirstOrderResponse> dataList = response.getDataList();
            for (OperateBoardFirstOrderResponse commissionResponse : dataList) {
                UserCoreDTO userCoreDTO = getUserTutorName(commissionResponse.getIrisUid());
                commissionResponse.setAdvisorHeadUrl(userCoreDTO.getHeadUrl());
                commissionResponse.setAdvisorNickName(userCoreDTO.getNickName());
                commissionResponse.setAdvisorUid(userCoreDTO.getUid());
            }
        }
        return response;
    }

    @Override
    public PaginationResponse<AdvisorBoardResponse> queryOperateBoard(
            PaginationRequest<AdvisorGroupTaskRequest> request) {
        //默认查询进行中和已结束状态
        if (CollectionUtils.isEmpty(request.getQueryCriteria().getTaskPhaseStatus())) {
            request.getQueryCriteria().setTaskPhaseStatus(Arrays.asList(TaskStatusEnum.BE_ONLINE.getStatus(),
                    TaskStatusEnum.OFFLINE.getStatus()));
        }

        Function<PaginationRequest<AdvisorGroupTaskRequest>, String> reqFunc =
                req -> GroupTaskBoardUtils.toAdvisorBoardBody(req);
        Function<AdvisorBoardDTO, AdvisorBoardResponse> resFunc =
                dto -> GroupTaskBoardUtils.toAdvisorBoardResponse(dto);

        PaginationResponse<AdvisorBoardResponse> result = operateBoardDependency
                .queryPageFromQufa(request, QuFaHttpConstant.OPERATE_BOARD, reqFunc, resFunc, AdvisorBoardDTO.class,
                        PaginationResponse.class);

        List<AdvisorBoardResponse> dataList = result.getDataList();
        if (!CollectionUtils.isEmpty(dataList)) {
            List<Integer> collect = dataList.stream().map(abr -> abr.getTaskPhaseId()).collect(Collectors.toList());
            CanJoinTaskRequest canJoinTaskRequest = new CanJoinTaskRequest();
            canJoinTaskRequest.setTaskPhaseIds(collect);
            Map<Integer, Integer> map = groupTaskBoardNewDependency.queryCanJoinTaskCount(
                    canJoinTaskRequest, QuFaHttpConstant.LIST_CAN_JOIN_TASK_COUNT);
            if (!map.isEmpty()) {
                result.getDataList().forEach(abr -> {
                    Integer canJoinCount = map.get(abr.getTaskPhaseId());
                    if (Objects.nonNull(canJoinCount) && canJoinCount > 0) {
                        Integer joinCount = abr.getTaskPhaseLeaderJoinCount();
                        Double joinCountRate = (double) joinCount / canJoinCount * 100;
                        BigDecimal bigDecimal = new BigDecimal(joinCountRate);
                        abr.setCanJoinTaskCount(canJoinCount);
                        abr.setJoinTaskRate(bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    }
                });
            }
        }
        return result;
    }

    @Override
    public GroupTaskPaginationResponse<OperateSecondBoardResponse> queryOperateSecondBoard(
            PaginationRequest<OperateBoardRequest> request) {
        String advisorUid = request.getQueryCriteria().getAdviserId();
        if (!StringUtils.isEmpty(advisorUid)) {
            request.getQueryCriteria().setIsAdviser(IsAdviserEnum.ADVISER.getStatus());
        }

        Function<PaginationRequest<OperateBoardRequest>, String> reqFunc =
                req -> GroupTaskBoardUtils.toJsonString(req).toJSONString();
        Function<OperateSecondBoardDTO, OperateSecondBoardResponse> resFunc =
                dto -> OperateBoardUtils.toOperateSecondBoardResponse(dto);

        GroupTaskPaginationResponse<OperateSecondBoardResponse> response = operateBoardDependency.queryPageFromQufa(
                request, QuFaHttpConstant.OPERATE_TASK_SECOND, reqFunc, resFunc, OperateSecondBoardDTO.class,
                GroupTaskPaginationResponse.class);

        if (!CollectionUtils.isEmpty(response.getDataList())) {
            List<OperateSecondBoardResponse> dataList = response.getDataList();
            for (OperateSecondBoardResponse secondBoardResponse : dataList) {
                handleAdvisorInfo(secondBoardResponse.getIrisUid(), secondBoardResponse);
                if (Objects.nonNull(secondBoardResponse.getIrisUid())) {
                    ChannelUserIdentifyDTO channelUserIdentifyDTO = userCoreDependency
                            .queryChannelAccount(secondBoardResponse.getIrisUid(),
                                    request.getQueryCriteria().getSaasId());
                    secondBoardResponse.setWechatUserUnionid(channelUserIdentifyDTO.getUnionId());
                }
            }
        }
        return response;
    }

    @Override
    public PaginationResponse<OperateThirdBoardResponse> queryOperateThirdBoard(
            PaginationRequest<OperateBoardThirdRequest> request) {
        Function<PaginationRequest<OperateBoardThirdRequest>, String> reqFunc =
                req -> OperateBoardUtils.toThirdBoardBody(req);
        Function<OperateThirdBoardDTO, OperateThirdBoardResponse> resFunc =
                dto -> OperateBoardUtils.toOperateThirdBoardResponse(dto);

        PaginationResponse<OperateThirdBoardResponse> response = operateBoardDependency.queryPageFromQufa(
                request, QuFaHttpConstant.OPERATE_TASK_THIRD, reqFunc, resFunc, OperateThirdBoardDTO.class,
                PaginationResponse.class);
        List<OperateThirdBoardResponse> dataList = response.getDataList();
        if (!CollectionUtils.isEmpty(dataList)) {
            dataList.stream().forEach(re -> {
                String irisUid = re.getIrisUid();
                if (Objects.nonNull(irisUid)) {
                    ChannelUserIdentifyDTO channelUserIdentifyDTO = userCoreDependency.queryChannelAccount(irisUid,
                            request.getQueryCriteria().getSaasId());
                    re.setWechatUserUnionid(channelUserIdentifyDTO.getUnionId());
                }
            });
        }

        return response;
    }

    @Override
    public PaginationResponse<UnJoinTaskResponse> listUnJoinTaskLeader(PaginationRequest<UnJoinTaskRequest> request) {

        Function<PaginationRequest<UnJoinTaskRequest>, String> reqFunc =
                req -> GroupTaskBoardUtils.toJsonString(req).toJSONString();
        Function<UnJoinTaskDTO, UnJoinTaskResponse> resFunc =
                dto -> OperateBoardUtils.toUnJoinTaskResponse(dto);

        PaginationResponse<UnJoinTaskResponse> response = operateBoardDependency.queryPageFromQufa(request,
                QuFaHttpConstant.LIST_UNJOIN_TASK_LEADER, reqFunc, resFunc, UnJoinTaskDTO.class,
                PaginationResponse.class);

        List<UnJoinTaskResponse> dataList = response.getDataList();
        if (CollectionUtils.isEmpty(dataList)) {
            return response;
        }

        List<String> uidList = Lists.newArrayListWithCapacity(dataList.size() * 2);
        for (UnJoinTaskResponse i : dataList) {
            uidList.add(i.getUid());
            uidList.add(i.getTutorUid());
        }

        uidList.removeAll(Collections.singleton(null));

        IrisUserWideListQueryRequest wideListQueryRequest = new IrisUserWideListQueryRequest();
        wideListQueryRequest.setUidList(uidList);
        wideListQueryRequest.setSaasId(request.getQueryCriteria().getSaasId());
        List<UserWideDTO> wideListResponse = userCoreDependency.batchQueryUserList(wideListQueryRequest);

        if (CollectionUtils.isEmpty(wideListResponse)) {
            return response;
        }

        Map<String, UserWideDTO> wideDTOMap = wideListResponse.stream()
                .collect(Collectors.toMap(UserWideDTO::getUid, Function.identity(), (v1, v2) -> v1));

        dataList.stream().forEach(i -> OperateBoardUtils.handleUserInfo(i, wideDTOMap));

        return response;
    }

    @Override
    public OperateBoardStatisticsResponse operateBoardStatistics(OperateBoardStatisticsRequest request) {

        //默认查询进行中和已结束状态
        if (CollectionUtils.isEmpty(request.getTaskPhaseStatus())) {
            request.setTaskPhaseStatus(Arrays.asList(TaskStatusEnum.BE_ONLINE.getStatus(),
                    TaskStatusEnum.OFFLINE.getStatus()));
        }

        Function<OperateBoardStatisticsRequest, String> reqFunc =
                req -> OperateBoardUtils.toOperateBoardStaticRequest(req);
        Function<OperateBoardStatisticsDTO, OperateBoardStatisticsResponse> resFunc =
                dto -> OperateBoardUtils.toOperateBoardStaticResponse(dto);

        return operateBoardDependency.queryObjectFromQufa(request, QuFaHttpConstant.SELLER_STATISTICS,
                reqFunc, resFunc, OperateBoardStatisticsDTO.class);
    }

    @Override
    public List<SpecialStageListsResponse> taskGroupSpecialStageLists(SpecialStageListsRequest request) {

        Function<SpecialStageListsRequest, String> reqFunc =
                req -> JSON.toJSONString(req);
        Function<SpecialStageListsDTO, SpecialStageListsResponse> resFunc =
                dto -> OperateBoardUtils.toSpecialStageListsResponse(dto);

        return operateBoardDependency.queryListFromQufa(request,
                QuFaHttpConstant.TASK_GROUP_SPECIAL_STAGE_LISTS, reqFunc, resFunc, SpecialStageListsDTO.class);
    }

    /**
     * 处理导师信息
     *
     * @param irisUid
     * @param secondBoardResponse
     * @param <T>
     */
    private <T extends AdvisorInfoResponse> void handleAdvisorInfo(String irisUid, T secondBoardResponse) {
        //UserCoreDTO userCoreDTO = getUserTutorName(irisUid);

        UserCoreDTO userCoreDTO = getUserByAdvisorUid(secondBoardResponse.getAdvisorUid());

        secondBoardResponse.setAdvisorHeadUrl(userCoreDTO.getHeadUrl());
        secondBoardResponse.setAdvisorNickName(userCoreDTO.getNickName());
        secondBoardResponse.setAdvisorUid(userCoreDTO.getUid());
    }

    /**
     * 根据团长uid获取对应导师信息
     *
     * @param uid
     */
    public UserCoreDTO getUserTutorName(String uid) {
        try {
            UserTutorRelationDTO userTutorRelationDTO = userCoreDependency.queryUserTutorRelation(uid);
            if (Objects.nonNull(userTutorRelationDTO) && Objects.nonNull(userTutorRelationDTO.getTutorUid())) {
                UserCoreDTO userCoreDTO = userCoreDependency.queryUserCoreInfo(userTutorRelationDTO.getTutorUid());
                if (Objects.nonNull(userCoreDTO)) {
                    return userCoreDTO;
                }
            }
        } catch (Exception e) {
            log.error("getUserTutorName error uid:{}", uid, e);
            throw new TRetailBizException(e);
        }
        return new UserCoreDTO();
    }

    /**
     * 根据导师uid获取对应导师信息
     *
     * @param uid
     */
    public UserCoreDTO getUserByAdvisorUid(String uid) {
        if (Objects.isNull(uid)) {
            return new UserCoreDTO();
        }
        try {
            UserCoreDTO userCoreDTO = userCoreDependency.queryUserCoreInfo(uid);
            if (Objects.nonNull(userCoreDTO)) {
                return userCoreDTO;
            }
        } catch (Exception e) {
            log.error("getUserByAdvisorUid error uid:{}", uid, e);
            throw new TRetailBizException(e);
        }
        return new UserCoreDTO();
    }

    /**
     * 根据导师uid查询下面关联的团长unionIds
     *
     * @param uid
     * @return
     */
    public List<String> getTutorRelations(String uid, Long saasId) {
        if (StringUtils.isEmpty(uid)) {
            throw new TRetailBizException("uid不能为空！");
        }
        PaginationRequest<StudentQueryRequest> paginationRequest = new PaginationRequest<>();
        StudentQueryRequest studentQueryRequest = new StudentQueryRequest();
        studentQueryRequest.setTutorUid(uid);
        paginationRequest.setQueryCriteria(studentQueryRequest);
        paginationRequest.setPageSize(1000);
        paginationRequest.setPageNum(1);
        PaginationResponse<UserTutorRelationDTO> userTutorRelations = userCoreDependency.queryTutorStudentList(
                paginationRequest);
        List<String> list = new ArrayList<>();
        final int segment = 10;
        if (!CollectionUtils.isEmpty(userTutorRelations.getDataList())) {
            List<String> collect = userTutorRelations.getDataList().stream().map(user -> user.getUid())
                    .collect(Collectors.toList());
            int size = collect.size();
            log.info("GroupTaskBoardServiceImpl getTutorRelations size:{},result:{}", size, JSON.toJSONString(collect));
            try {
                List<CompletableFuture<ChannelAccountQueryResponse>> futures = new ArrayList<>();
                List<List<String>> partition = Lists.partition(collect, segment);
                for (List<String> part : partition) {
                    BatchQueryChannelAccountRequest request = new BatchQueryChannelAccountRequest();
                    request.setSaasId(saasId);
                    request.setUserGroup(UserGroup.GROUP_C.getType());
                    request.setUidList(part);
                    futures.add(CompletableFuture.supplyAsync(() ->
                                    userCoreDependency.batchQueryChannelAccount(request).getData(),
                            queryExecutor));
                }
                for (CompletableFuture<ChannelAccountQueryResponse> channelAccount : futures) {
                    ChannelAccountQueryResponse channelAccountQueryResponse = channelAccount.get();
                    if (Objects.nonNull(channelAccountQueryResponse)) {
                        List<UserChannelAccountDTO> userChannelAccountDTOS = channelAccountQueryResponse
                                .getChannelAccountDTOList();
                        if (!CollectionUtils.isEmpty(userChannelAccountDTOS)) {
                            for (UserChannelAccountDTO userChannelAccountDTO : userChannelAccountDTOS) {
                                ChannelUserIdentifyDTO userIdentifyDTO = userChannelAccountDTO
                                        .getChannelUserIdentifyDTO();
                                if (userIdentifyDTO != null && !StringUtils.isEmpty(userIdentifyDTO.getUnionId())) {
                                    list.add(userIdentifyDTO.getUnionId());
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                log.error("查询导师对应团长unionId出错，导师uid:{}", uid, e);
                throw new TRetailBizException("导师uid:{},查询团长unionId出错", uid);
            }
        }
        List<String> result = list.stream().distinct().collect(Collectors.toList());
        log.info("导师uid:{},GroupTaskBoardServiceImpl queryGroupUnionId result:{}", uid, result);
        return result;
    }

}